package nciae.db.controller;

import nciae.db.common.CommonResult;
import nciae.db.pojo.dto.ApiCourseDto;
import nciae.db.pojo.dto.ApiGetTableDto;
import nciae.db.pojo.entity.Course;
import nciae.db.pojo.vo.ApiCourseFilesVo;
import nciae.db.pojo.vo.ApiTimeTableVO;
import nciae.db.pojo.vo.CourseFilesVo;
import nciae.db.pojo.vo.apiCourseVo;
import nciae.db.service.CourseService;
import nciae.db.service.ILogService;
import nciae.db.utils.FileUploadUtils;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDPage;
import org.apache.pdfbox.pdmodel.PDPageContentStream;
import org.apache.pdfbox.pdmodel.font.PDType1Font;
import org.apache.pdfbox.rendering.ImageType;
import org.apache.pdfbox.rendering.PDFRenderer;
import org.apache.poi.sl.usermodel.Slide;
import org.apache.poi.xslf.usermodel.XMLSlideShow;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.poi.xwpf.usermodel.XWPFParagraph;
import org.docx4j.Docx4J;
import org.docx4j.convert.out.pdf.viaXSLFO.PdfSettings;
import org.docx4j.fonts.IdentityPlusMapper;
import org.docx4j.openpackaging.exceptions.Docx4JException;
import org.docx4j.openpackaging.packages.WordprocessingMLPackage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

@Controller
@CrossOrigin(origins = "*", allowedHeaders = "*")
public class TimeConrtoller {
    @Autowired
    private CourseService courseService;

    //获取所有课表信息
    @RequestMapping( "/api/timeTable")
    @ResponseBody
    public CommonResult<List<ApiTimeTableVO>> timeTable(@RequestBody ApiTimeTableVO apiTimeTableVO) {
        //        通过项目id查询课表
        Integer projectId = apiTimeTableVO.getProjectId();
        System.out.println(projectId);
//        return null;
        return courseService.apiInfo(projectId);
    }



    //移动端获取课程详细信息
    @RequestMapping("/api/getCourseFiles")
    @ResponseBody
    public CommonResult<Course> getCourseFiles(@RequestBody apiCourseVo courseId) {
        CommonResult<Course> result = new CommonResult<>();
        try {
            Course course = courseService.getById(courseId.getCourseId());
            if (course != null) {
                System.out.println(course.toString());
                result.setCode(0);
                result.setMsg("获得相关信息");
                result.setData(course);
            } else {
                result.setCode(400);
            }
        } catch (Exception e) {
            result.setCode(-1);
        }
        return result;
    }

    //移动端获得当堂课的所有课件信息
    @RequestMapping("/api/getApiCourseFiles")
    @ResponseBody
    public CommonResult<CourseFilesVo> getApiCourseFiles(@RequestBody apiCourseVo courseId) {
        CommonResult<CourseFilesVo> result = new CommonResult<>();
        try {
            result = courseService.getCourseFiles(courseId.getCourseId());
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        return result;
    }

    //获得文件的url进行预览
    @RequestMapping("/api/getFileUrl")
    @ResponseBody
    public CommonResult<ApiCourseFilesVo> getFileUrl(@RequestBody ApiCourseDto apiCourseDto) {
        CommonResult<ApiCourseFilesVo> result = new CommonResult<>();
        try {
            result = courseService.getUrlFiles(apiCourseDto.getCourseId(), apiCourseDto.getFileName());
        } catch (Exception e)
        {
            throw new RuntimeException(e);
        }
        return result;
    }




}

















